const ajax = function() {
    this.get = function(url,param) {
        const xhr = new XMLHttpRequest()
        // param为原始数据类型
        xhr.open('get',url + '?param=' + param,true) // 第三个参数异步与否
        xhr.onreadystatechange = function() {
            if(xhr.readyState === 4 && xhr.status === 200) {
                fn(xhr.responseText)
            }
        }
        xhr.send()
    }
    this.post = function(url, data) {
        const xhr = new XMLHttpRequest()
        xhr.open('post', url, true)
        xhr.setRequestHeader('Content-type','application/json') // 决定传数据格式
        xhr.onreadystatechange = function() {
            if(xhr.readyState === 4 && xhr.status === 200) {
                fn(xhr.responseText)
            }
        }
        xhr.send(JSON.stringify(data))
    }
}